﻿@model ArivisTests.Models.TestRun
@using ArivisTests.Models;
@using ArivisTests.Views;

@{
    ViewBag.Title = "Edit";
    IEnumerable<SelectListItem> availableTester = ViewBag.Tester;
    var style = new { style = "width:50px;text-align:right;" };
}

@section Navigation{
    @Html.ActionLink("Test Runs", "Index", "TestRun") &rsaquo;
    @Html.ActionLink(Model.Name, "Edit", "TestRun", new { id = Model.Id }, null) &rsaquo;
    Assign Tester
}

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>TestRun</legend>

        @Html.HiddenFor(model => model.Id)

        <table id="tester" class="editor-table">
            <tr>
                <th>Tester</th>
                <th>Availability</th>
            </tr>
            @foreach (var tester in availableTester)
            {
                <tr>
                    <td>@Html.CheckBox("user_" + tester.Value) @tester.Text</td>
                    <td>@Html.TextBox("available_" + tester.Value, 10, style)</td>
                </tr>
            }
        </table>
        <a href="#" onclick="jQuery('#tester input[type=checkbox]').attr('checked',true); return false;">Select All</a> |
        <a href="#" onclick="jQuery('#tester input[type=checkbox]').attr('checked',false); return false;">Select None</a>
        
        <table style="width:100%">
            <tr>
                <th style="width:40%">Scenario</th>
                <th>Runs</th>
            </tr>
        </table>
        <div style="max-height: 330px; overflow-y: auto; border-top:1px solid #d8d8d8; border-bottom:1px solid #d8d8d8">
        <table style="margin-top:0;width:100%" id="scenarios">
            @foreach (var group in Model.Tests.GroupBy(x => x.Scenario).OrderBy(group => group.Key.Id))
            {
                <tr>
                    <td style="width:40%">@group.Key.Name</td>
                    <td>@Html.TextBox("count_" + group.Key.Id, group.Count(), style)</td>
                </tr>
            }        
        </table>
        </div>
        <p>
            Runs: <input type="text" value="2" id="runs" maxlength="5" style="width:50px;text-align:right;" />&nbsp;
            <a href="#" onclick="jQuery('#scenarios input[type=text]').val(jQuery('#runs').val()); return false;">Apply To All</a>
        </p>
        <p>
            <input type="submit" value="Assign" />
        </p>
    </fieldset>
}

<p>
@Html.ActionLink("View", "Details", "TestRun", new { id=Model.Id }, null) |
@Html.ActionLink("Edit", "Edit", "TestRun", new { id=Model.Id }, null) |
@Html.ActionLink("Delete", "Delete", "TestRun", new { id=Model.Id }, null) |
@Html.ActionLink("Assign Tester Manual", "Manual", "AssignTest", new { id = Model.Id }, null)
</p>